package com.els.search.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.els.search.entity.FakeNews;
import com.els.search.service.FakeNewsService;
import com.els.search.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @title: IndexSearchController
 * @projectName fake-baidu
 * @Date: 2021/7/1 21:27
 * @Author: lei.yu-esint
 * @Description:
 */
@RestController
public class IndexSearchController {

    @Autowired(required = false)
    private FakeNewsService fakeNewsService;

    @Autowired(required = false)
    private GoodsService goodsService;

    @RequestMapping("/getIndexPushNews/{pages}/{size}")
    public String getIndexPushNews(@PathVariable String pages,@PathVariable String size){
        return null;
    }

    /**
     * 百度搜索-联想词查询-[数据源：MySQL]
     * @param keyword
     * @param page
     * @param size
     * @return
     */
    @RequestMapping("/getIndexKeywords/{keyword}/{page}/{size}")
    public String getIndexKeywords(@PathVariable String keyword,@PathVariable String page,@PathVariable String size){
        IPage<FakeNews> list=fakeNewsService.selectData(keyword,page,size);
        String json=JSON.toJSON(list).toString();
        return json;
    }

    /**
     * 百度搜索-联想词查询-[数据源：ES]
     * @param keyword
     * @param page
     * @param size
     * @return
     */
    @RequestMapping("/getIndexKeywordsEs/{keyword}/{page}/{size}")
    public String getIndexKeywordsEs(@PathVariable String keyword,@PathVariable String page,@PathVariable String size){
        String json=fakeNewsService.selectDataEs(keyword,page,size);
        return json;
    }

    /**
     * 新增新闻
     * @return
     */
    @RequestMapping("/addNews")
    public FakeNews addNews(){
        FakeNews fakeNews=fakeNewsService.addData();
        return fakeNews;
    }

}
